<!--查询用户信息-->
<template>
  <el-container>
    <el-header>
      <h1>查询用户信息</h1>
    </el-header>
    <el-main>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="邮箱地址" prop="mail"/>
        <el-table-column label="名字" prop="username"/>
        <el-table-column label="密码">
          <template #default="data">
            <span> {{ data.row.userpwd }} （md5加密）</span>
          </template>
        </el-table-column>
        <el-table-column label="性别">
          <template #default="data">
            <span>{{ data.row.sex == 0 ? '男' : '女' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="身份证号" prop="idcard"/>
        <el-table-column label="所属班级" prop="grade"/>
        <el-table-column label="权限等级">
          <template #default="data">
            <span>{{ LevelJudge(data.row.level) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间">
          <template #default="data">
            <span>{{ DateJudge(data.row.data) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button type="danger" @click="del(scope.$index, scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </el-container>
</template>

<script>
import {UserList} from "@/components/request/UserList";
import {LevelJudge} from "@/components/function/LevelJudge";
import {DateJudge} from "@/components/function/DateJudge";
import {ElMessageBox} from "element-plus";
import {delectmail} from "@/components/request/delectmail";

export default {
  name: "ListUser",
  data() {
    return {
      tableData: null
    }
  },
  mounted() {
    this.demo();
  },
  methods: {
    LevelJudge,
    DateJudge,
    demo() {
      UserList(data => {
        this.tableData = data;
      })
    },
    del(scope, row) {
      ElMessageBox.confirm(
          '你确定要删除' + row.mail,
          'Warning',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }
      ).then(() => {
        delectmail(row.mail);
        ElMessageBox.alert('删除成功', 'Title', {
          confirmButtonText: 'OK',
          callback: () => {
            this.demo();
          }
        })
      }).catch(() => {
        return null;
      })
    }
  },
}
</script>

<style scoped>

</style>